﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.NHibernateHelper;
using Domain.Entity;
using DataAccess.AbstractRepository;
using NHibernate;

namespace DataAccess.Repository
{
    public class StaffRepository : NHibRepository<Staff>, IStaffRepository
    {
        public StaffRepository(NHibContext context)
            : base(context)
        {
        }

        public virtual IList<Staff> GetAllStaffs(string column, string value)
        {
            string hsql = "from Staff where " + column + " like '%" + value + "%'";
            IQuery query = Session.CreateQuery(hsql);
            return query.List<Staff>();
        }

        public Staff GetStaffByEmail(string email)
        {
            Staff staff = null;
            string hsql = "from Staff where email='" + email + "'";
            IQuery query = Session.CreateQuery(hsql);
            IList<Staff> lstStaff = query.List<Staff>();
            if (lstStaff.Count > 0)
            {
                staff = lstStaff.FirstOrDefault<Staff>();
            }
            return staff;
        }
    }
}
